/*
 * @Author: your name
 * @Date: 2021-10-09 14:39:41
 * @LastEditTime: 2021-11-12 16:51:14
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \epet_back\routes\index.js
 */
const Router = require('koa-router')
const router = new Router()

const swiperRouter = require('./swiperRouter')
const bannerRouter = require('./bannerRouter')
const navbtnRouter = require('./navbtn')
const goodsRouter = require('./goodsRouter')
const goodRankRouter = require('./goodRank')
const classifyRouter = require('./classifyRouter')
const userRouter = require('./userRouter')
const cartRouter = require('./cartRouter')
const relationRouter = require('./relation')
const NewRouter = require('./newRouter')
let qn = require('../utils/may');  //导入七牛文件
router.use('/api/v1/cart',cartRouter.routes(),cartRouter.allowedMethods())
router.use('/api/v1/user',userRouter.routes(),userRouter.allowedMethods())
router.use('/api/v1/classify',classifyRouter.routes(),classifyRouter.allowedMethods())
router.use('/api/v1/goodRank',goodRankRouter.routes(),goodRankRouter.allowedMethods())
router.use('/api/v1/swiper',swiperRouter.routes(),swiperRouter.allowedMethods())
router.use('/api/v1/banner',bannerRouter.routes(),bannerRouter.allowedMethods())
router.use('/api/v1/navbtn',navbtnRouter.routes(),navbtnRouter.allowedMethods())
router.use('/api/v1/goods',goodsRouter.routes(),goodsRouter.allowedMethods())
router.use('/api/v1/relation',relationRouter.routes(),relationRouter.allowedMethods())
router.use('/api/v1/new',NewRouter.routes(),NewRouter.allowedMethods())
//上传图片
router.post("/update",  (req, routerRes)=> {
    // req.body = req
    console.log('触发1')
    try {
    console.log('触发2')
     qn.update(req, function (res) {
    console.log('触发3')
            console.log('res',res);
            if (res.status == 0) {
                  req.body = {
                   data: routerRes.json(result(res.data, true))
                  }
            } else {
                req.body = {
                    data: routerRes.json(result(res.data, true))
                   }
            }
        });
    } catch (err) {
    console.log('触发4')
        if (err) {
            console.log('trycatch报错====', err);
        }
    }
})
module.exports = router